package gameadminlogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/game/internal/svc"
	"navi-mumbai/app/rpc/game/pb"
	"navi-mumbai/app/rpc/model/pg/game"
	"navi-mumbai/common/key/dbkey"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGameLogic {
	return &AddGameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加游戏
func (l *AddGameLogic) AddGame(in *pb.AddGameReq) (*pb.AddGameResp, error) {
	defer utils.RecoverPanic()

	gg := game.Game{
		GameId:         in.GameId,
		GameType:       in.GameType,
		GameName:       in.GameName,
		GameLogo:       in.Logo,
		ProviderId:     in.ProviderId,
		ProviderGameId: in.GGameId,
		GameUrl:        in.GameUrl,
		InstantId:      in.InstantId,
		State:          dbkey.Enable,
	}

	_, err := l.svcCtx.GameModel.Insert(l.ctx, &gg)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.AddGameResp{}, nil
}
